#include "Alice/Systems/ForceSys.h"
#include "Alice/Core/World.h"
#include "Alice/Components/TransformComp.hpp"
#include "Alice/Components/ForceComp.hpp"

namespace Alice
{

void ForceSys::OnUpdate()
{
    for (auto entity : entitys)
    {
        ForceComp& f_comp = world->GetComp<ForceComp>(entity);
        TransformComp& tf_comp = world->GetComp<TransformComp>(entity);
        // 处理四个方向上的力
        if (f_comp.up > 0)
        {
            Timer& up_timer = f_comp.timers[0];
            up_timer.Clock();
            tf_comp.position.y -= f_comp.up;
        }
        if (f_comp.down > 0)
        {
            Timer& down_timer = f_comp.timers[1];
            down_timer.Clock();
            tf_comp.position.y += f_comp.down;
        }
        if (f_comp.left > 0)
        {
            Timer& left_timer = f_comp.timers[2];
            left_timer.Clock();
            tf_comp.position.x -= f_comp.left;
        }
        if (f_comp.right > 0)
        {
            Timer& right_timer = f_comp.timers[3];
            right_timer.Clock();
            tf_comp.position.x += f_comp.right;
        }
        // 获取重力的计时器
        Timer& g_timer = f_comp.timers[4];
        g_timer.Clock();
        tf_comp.position.y += f_comp.gravity;
    }
}

} // namespace Alice
